﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "OwnerPtr.h"

#include <QMap>
#include <QIcon>
#include <QTreeWidget>
#include "UIComponent.h"
#include "QFamilyTreeWidgetUtil.h"

namespace gcmp
{
    class IDocument;
}

namespace Sample
{
    class TestDropEventHandler;

    class UICOMPONENT_EXPORT QFamilyTreeWidget : public QTreeWidget
    {
        Q_OBJECT
    public:
        QFamilyTreeWidget(QWidget *parent = NULL);
        ~QFamilyTreeWidget();

    public:
        void UpdateView(gcmp::IDocument* pDoc);

    protected:
        void mouseMoveEvent(QMouseEvent *event) override;
        void mousePressEvent(QMouseEvent *event) override;

        public slots:
        void CreateFamilyInstance();
        void RenameFamily();
        void EditFamily();
        void LoadFamily();
        void SaveAsFamily();
        void RemoveFamily();

        private slots:
        void OnFamilyTreeItemDoubleClicked(QTreeWidgetItem *item, int column);

    private:
        void performDrag();
        void UpdateFamilyTreeItemContextMenu(const QList<QTreeWidgetItem*>& selectedItem);

    private:
        QPoint     m_startDragPoint;
        //树的右键菜单
        QMenu* m_treeMenu;

        // 缓存图标，以避免每次从资源加载
        QIconMap m_icons;

        //自响应的默认族命令
        bool m_bShowFamilyManagementMenuItem;

        gcmp::OwnerPtr<TestDropEventHandler> m_opDropEventHandler;
    };
}

